package com.lhy.framework.beans.factory.support;

import com.lhy.framework.BeansException;
import com.lhy.framework.beans.factory.factory.BeanDefinition;

/**
 * @ClassName AbstractAutowireCapableBeanFactory
 * @Description
 * @Author lihaiyang
 * @Date 2022/9/8 22:40
 * @Version 1.0
 */
public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFactory {

    @Override
    public Object createBean(String beanName, BeanDefinition beanDefinition)  throws BeansException {
        Object bean = null;
        try {
            bean = beanDefinition.getClazz().newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new BeansException("Instantiation of bean failed", e);
        }
        addSingleton(bean.getClass().getSimpleName(), bean);
        return bean;
    }
}
